#include <vector>
using namespace std;
/*
 * @lc app=leetcode.cn id=11 lang=cpp
 *
 * [11] 盛最多水的容器
 */

// @lc code=start
class Solution {
public:
    int maxArea(vector<int>& height) {
        int i = 0, j = height.size() - 1;
        int res = 0;
        while (i < j) {
            int internal = j - i;
            res = max(res, (j - i) * min(height[i], height[j]));
            if (height[i] < height[j]) {
                for (int t = i + 1; t < height.size(); t++) {
                    if (height[t] > height[i]) {
                        i = t;
                        break;
                    }
                }
            }
            else {
                for (int t = j - 1; t >= 0; t--) {
                    if (height[t] > height[j]) {
                        j = t;
                        break;
                    }
                }
            }
            if (internal == j - i) break;
        }
        return res;
    }
};
// @lc code=end

